$('#department-company_id').change(function () {
    var company = $(this);
    var branch = $('#department-branch_id');
    $.getJSON('../branch/list?id=' + company.val(), function (data) {
        branch.empty();
        $.each(data, function (index, value) {
            branch.append('<option value="' + value.id + '">' + value.name + '</option>');
        });
    });
});

$('#branchCreateModal').on('show.bs.modal', function () {
    $('.modal-body', this).load('create');

});

$('#branchCreateModal').on('submit', '#branchForm', function () {
    var form = $(this);
    var modal = $('#branchCreateModal');
    $.post(form.attr('action'), form.serialize()).done(function (data) {
        if (data.result) {
            modal.modal('hide');
        } else {
            console.log(data.error);
        }
    });
    return false;
});